package common

import (
	"fmt"
	"time"
)

func FormatDurationSinceNow(startTime time.Time) string {
	duration := time.Since(startTime)

	if duration < 0 {
		duration = -duration // 保证正数
	}

	days := int(duration.Hours()) / 24
	if days > 0 {
		return fmt.Sprintf("%dd", days)
	}

	hours := int(duration.Hours())
	if hours > 0 {
		return fmt.Sprintf("%dh", hours)
	}

	minutes := int(duration.Minutes())
	if minutes > 0 {
		return fmt.Sprintf("%dm", minutes)
	}

	seconds := int(duration.Seconds())
	return fmt.Sprintf("%ds", seconds)
}
